package com.opencv.domain;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @author qz.wu
 * @date 2021/12/28 14:11
 * @descriptions 接口返回统一封装
 */
@Api(tags = "接口返回统一封装")
public class ResponseMsg<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 时间戳
     */
    @ApiModelProperty(name = "timestamp", value = "时间戳")
    private long timestamp;

    /**
     * 业务响应码
     */
    @ApiModelProperty(name = "code", value = "业务响应码")
    private int code;

    /**
     * 提示内容
     */
    @ApiModelProperty(name = "msg", value = "提示内容")
    private String msg;

    /**
     * 结果集
     */
    @ApiModelProperty(name = "data", value = "响应结果集")
    private T data;

    /**
     * 错误结果集
     */
    @ApiModelProperty(name = "errorData", value = "错误结果集")
    private Object errorData;

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Object getErrorData() {
        return errorData;
    }

    public void setErrorData(Object errorData) {
        this.errorData = errorData;
    }

    public ResponseMsg(int code, String msg, T data, Object errorData) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.errorData = errorData;
    }

    public static <T> ResponseMsg<T> success(T data) {
        return new ResponseMsg<>(200, "成功", data, null);
    }


    public static <T> ResponseMsg<T> success(String message) {
        return new ResponseMsg<>(200, message, null, null);
    }
}
